/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


import java.net.InetAddress;
import java.net.UnknownHostException;

import morseSide.SocketOut;

public class InterfaceMorseFrameselfOut implements Runnable{

    SocketOut socket;
    String m;
    

    public InterfaceMorseFrameselfOut(int port) {
        try {
            socket = new SocketOut(InetAddress.getLocalHost(), port);
        } catch (UnknownHostException ex) {
            System.out.println("Impossible de créer le socket OUT");
        }
    }

    public void sendMessage() throws InterruptedException {
            m = "id1 atrv.motion set_speed [2, -1]";
            while (true){
                socket.sendMessage(m);
                m = "id1 atrv.motion set_speed [-1, 2]";
                Thread.sleep(2000);
                socket.sendMessage(m);
                m = "id1 atrv.motion set_speed [2, -1]";
                Thread.sleep(2000);
            }
    }
    
    public String sendMsg(String action) {
    	
    	String erreur = "No error";
    	
    	if (action.contains("SwitchAlarmOn"))
    		socket.sendMessage("{\"mode\":\"play\"}");
    	else
    		socket.sendMessage("{\"mode\":\"pause\"}");
    	
    	return erreur;
    }
    
    @Override
    public void run() {
        try {
            sendMessage();
        } catch (InterruptedException ex) {
            System.out.println("Problème avec les sleeps de InterfaceMorseFrameself OUT");
        }
    }
}